//
//  ChoosePlayerController.m
//  soccer
//
//  Created by 上官千城 on 15/9/10.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "ChoosePlayerController.h"
#define item WIDTH/4
@interface ChoosePlayerController ()

@end

@implementation ChoosePlayerController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //球员列表
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(savePlaer)];
    
}
//保存设置
-(void)savePlaer
{
    NSLog(@"保存");
}

//协议方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]init];
        //最喜欢的球星
        if (indexPath.section == 0 && indexPath.row == 0) {
            self.bestPlayer = [UIButton buttonWithType:UIButtonTypeCustom];
            self.bestPlayer.frame = CGRectMake(10, 10, 60, 60);
            [self.bestPlayer setImage:[UIImage imageNamed:@"2013103109282582218_01@2x"] forState:UIControlStateNormal];
            
            [self.bestPlayer addTarget:self action:@selector(deletePlayer) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:self.bestPlayer];
            // "-"
            UILabel *sub = [[UILabel alloc]initWithFrame:CGRectMake(self.bestPlayer.frame.size.width-8, self.bestPlayer.frame.origin.y-10, 10, 10)];
            sub.text = @"-";
            sub.textAlignment = NSTextAlignmentCenter;
            sub.backgroundColor = [UIColor greenColor];
            [self.bestPlayer addSubview:sub];
        }
        //其他喜欢的球星
        if (indexPath.section == 0 && indexPath.row == 1) {
            
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //所有球星
    if (indexPath.section == 1) {
        int k = 1;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
                imgButton.frame = CGRectMake(5 + item * j , 10 + item * i, item , item );
                NSString *str = [NSString stringWithFormat:@"2013103109282582218_%.2d",k];
                [imgButton setImage:[UIImage imageNamed:str] forState:UIControlStateNormal];
                [cell addSubview:imgButton];
                k++;
            }
        }
    }
    return cell;
}
//行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return 1;
    }
    return 2;
}
//区数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 80;
    }
    return item * 6;
}
//删除最喜欢球员
-(void)deletePlayer
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
